local textoIngresado=service.getText(node)
local textChunks={}
local maxChunkSize=4000
while #textoIngresado>maxChunkSize
local chunkEnd=maxChunkSize
while string.sub(textoIngresado,chunkEnd,chunkEnd) ~= " " and chunkEnd>1
chunkEnd=chunkEnd-1
end
table.insert(textChunks,string.sub(textoIngresado,1,chunkEnd))
textoIngresado=string.sub(textoIngresado,chunkEnd+1)
end
table.insert(textChunks,textoIngresado)
require"import" import "android.os.*" import "android.speech.tts.*" import "java.io.*" local tts=TextToSpeech(this,function(status) if status==TextToSpeech.ERROR service.asyncSpeak("TextToSpeech Tidak dapat digunakan") elseif status==TextToSpeech.SUCCESS service.asyncSpeak("Berhasil menggunakan TextToSpeech") synthesizetofile() end end) tts.setOnUtteranceProgressListener(UtteranceProgressListener{onStart=function service.playSoundGestureBegin() end,onStop=function service.playSoundGestureEnd() end,onDone=function service.playSoundScroll(1) end,onError=function service.beep() end}) function synthesizetofile() local folderpath=Environment.getExternalStorageDirectory().getAbsolutePath().."/Rekaman TTS" local file=File(folderpath) if not file.exists() file.mkdirs() end for i,v in ipairs(textChunks) local filename="TTS-"..i..os.date"-%Y%m%d-%H%M%S.wav" local params={[TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID]=filename} tts.synthesizeToFile(v,params,folderpath.."/"..filename) end end return true